Skip to content

London | 26-ITP-Jan | Abdul Moiz | Sprint 2 | Book Library#385

Closed
A-Moiz wants to merge 3 commits into
CodeYourFuture:mainfrom
A-Moiz:book-library-debug
Closed

London | 26-ITP-Jan | Abdul Moiz | Sprint 2 | Book Library#385
A-Moiz wants to merge 3 commits into
CodeYourFuture:mainfrom
A-Moiz:book-library-debug

Conversation

@A-Moiz
Copy link
Copy Markdown

@A-Moiz A-Moiz commented Mar 3, 2026

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

  • Resolved all known bugs
  • Reset all values after adding book to improve UX

Questions

N/A

@A-Moiz A-Moiz added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 3, 2026
@ykamal ykamal added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Mar 16, 2026
Copy link
Copy Markdown

@ykamal ykamal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! 👍 Things look mostly right. Well done. There are a few things that need a bit of work. I've left comments below. Let me know if you have any questions.

Comment thread debugging/book-library/script.js Outdated
function populateStorage() {
if (myLibrary.length == 0) {
if (myLibrary.length === 0) {
let book1 = new Book("Robison Crusoe", "Daniel Defoe", "252", true);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love to see some OOP code. Since the class you're referencing here is declared further down the file, for the sake of readability and code organisation, I recommend moving the class definition to much higher, or to the beginning of this file.

Comment thread debugging/book-library/script.js Outdated
function populateStorage() {
if (myLibrary.length == 0) {
if (myLibrary.length === 0) {
let book1 = new Book("Robison Crusoe", "Daniel Defoe", "252", true);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

book1 is not getting reassigned later, so using a const keyword will make it safer in the same scope. It's still going to allow you to run object mutations where applicable. but it ensures that you cannot redeclare a variable with the same name inside the same scope.
Same for book2

Comment thread debugging/book-library/script.js Outdated
pages.value == null ||
pages.value == ""
) {
if (title.value === "" || author.value === "" || pages.value === "") {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good validation check 👍
However, if you do not remove unnecessary whitespaces from the start and the end, " " will pass through this check as it's a bunch of valid characters and is not an empty string. How do you think you could counter this?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this has been adressed

Comment thread debugging/book-library/script.js Outdated
let book = new Book(
title.value,
author.value,
String(pages.value),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good safe practice, but there is most likely no need to convert this into a string, as all input values are always returned (usually) as strings, unless something like this is used: https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/valueAsNumber

Comment thread debugging/book-library/script.js Outdated
this.title = title;
this.author = author;
this.pages = pages;
this.check = check;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is JavaScript, do you think we should ensure that these constructor arguments are provided in the right data type?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • and data range (numbers)

Comment thread debugging/book-library/script.js Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

render() appears to be called twice on page load. Perhaps you should create a sequence of this from the root function call and not inside here?

} else {
readStatus = "Yes";
}
changeBut.innerText = readStatus;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you come across Ternary Operator? Could make the code cleaner:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_operator

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@A-Moiz there's an easier way to do this:

const myBool = anotherBool ? "Yes" : "No";

Comment thread debugging/book-library/script.js Outdated
delBut.className = "btn btn-warning";
delBut.innerHTML = "Delete";
delBut.addEventListener("clicks", function () {
delButton.id = i + 5;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see that you are trying to avoid duplicate IDs. Nice approach. However, the approach is hard-coding a specific number, and the outcome could be inconsistent.
You could just use delButton.id = "delButton_" + i or such tactics. That'll make them truly unique. Obviously, use string interpolation with backticks. I can't write that here.

Comment thread debugging/book-library/script.js Outdated
delButton.id = i + 5;
deleteCell.appendChild(delButton);
delButton.className = "btn btn-warning";
delButton.innerHTML = "Delete";
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use textContent as it parses the provided value as a string, whereas innerHTML parses it as HTML and should only be used if the change contains actual HTML. You can also use innerText for static text. textContent may be faster for most things.

deleteCell.appendChild(delButton);
delButton.className = "btn btn-warning";
delButton.innerHTML = "Delete";
delButton.addEventListener("click", function (e) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a better way to do this would be using data- attributes. You're using i inside a closure which, while fine, is not the best practice.
jQuery has excellent APIs for using data attributes. Even with core JavaScript, if you can master data attributes, you will no longer need to do these, and can use HTML itself for storing that reference.
https://developer.mozilla.org/en-US/docs/Web/HTML/How_to/Use_data_attributes

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much more appropriate as this isn't dealing with stale data inside a closure

@ykamal ykamal added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Mar 16, 2026
@A-Moiz
Copy link
Copy Markdown
Author

A-Moiz commented Mar 18, 2026

Hi @ykamal , I've made all the changes you requested. Let me know if you anymore recommendations.

@A-Moiz A-Moiz added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Mar 18, 2026
@ykamal
Copy link
Copy Markdown

ykamal commented Apr 3, 2026

Apologies, I have not been well. Going to look now.

} else {
readStatus = "Yes";
}
changeBut.innerText = readStatus;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@A-Moiz there's an easier way to do this:

const myBool = anotherBool ? "Yes" : "No";

Comment thread debugging/book-library/script.js Outdated
pages.value == null ||
pages.value == ""
) {
if (title.value === "" || author.value === "" || pages.value === "") {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this has been adressed

deleteCell.appendChild(delButton);
delButton.className = "btn btn-warning";
delButton.innerHTML = "Delete";
delButton.addEventListener("click", function (e) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much more appropriate as this isn't dealing with stale data inside a closure

@ykamal ykamal added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Apr 3, 2026
@A-Moiz
Copy link
Copy Markdown
Author

A-Moiz commented Apr 6, 2026

Hi @ykamal , thanks for your comments! I've made the changes. Please have another look and let me know what you think.

@A-Moiz A-Moiz added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Apr 6, 2026
@cjyuan
Copy link
Copy Markdown
Contributor

cjyuan commented Apr 18, 2026

@A-Moiz It seems your changes have addressed @ykamal comments, I will mark this PR as "Complete" on behalf of the reviewer.

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Apr 18, 2026
@illicitonion
Copy link
Copy Markdown
Member

Closing PR because the January ITP run has finished. Feel free to re-open if you're still working on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants